package com.samuel.test;

import java.util.ArrayList;
import java.util.List;

public class Fenye {

    public static  List<Integer>  paginationBySubList(List list,int pagesize,int page) {

        page = page<=0?1:page;
        int totalcount = list.size();
        int pagecount = 0;
        int m = totalcount % pagesize;
        pagecount = m > 0 ? totalcount / pagesize + 1 : totalcount / pagesize;

        List<Integer> subList = page <= pagecount ?  (m == 0 ? list.subList((page - 1) * pagesize, pagesize * (page)) : (page == pagecount?list.subList((page - 1) * pagesize, totalcount) : list.subList((page - 1) * pagesize, pagesize * (page)))): new ArrayList<>();
        System.out.println(subList.toString());
        return subList;
    }



    public static void main(String[] args) {

        List<Integer> list=new ArrayList<Integer>();
        for(int i=1;i<52;i++){
            list.add(i);
        }
        paginationBySubList(list,20,-1);
        paginationBySubList(list,20,0);
        paginationBySubList(list,20,1);
        paginationBySubList(list,20,2);
        paginationBySubList(list,20,3);
        paginationBySubList(list,20,4);
        paginationBySubList(list,20,5);


    }
}
